﻿using System.Collections.Generic;
using EmbeddedSharp.Core;

//using VIJAY.MATH;

namespace Zove.Runtime.Core.Numerics {
    /// <summary>
    /// 
    /// </summary>
    public class EquationGroup {
        public EquationGroup(string[] eg) {
            Elements = new List<string>();
            Equations = new List<string>();

            Equations.AddRange(eg);
        }

        public EquationGroup(List<string> eg)
            : this(eg.ToArray()) {
        }

        public List<string> Equations { get; set; }

        public List<string> Elements { get; set; }

        public override int GetHashCode() {
            return base.GetHashCode();
        }

        public override bool Equals(object obj) {
            if (!obj.GetType().Equals(typeof(EquationGroup))) {
                return false;
            }

            var eg = (EquationGroup)obj;

            foreach (string e in eg.Equations) {
                if (!Equations.Contains(e)) {
                    return false;
                }
            }

            return true;
        }

        public double[] Evaluate() {
            var s = new List<string>();

            foreach (string e in Equations) {
                string m = e + "=0";
                s.Add(m);

                Utils.Debugging("expr: " + m);
            }

            // TODO set up nonlinear equations
            // NonLinear.SetSystem(s.ToArray());
            var r = new double[s.Count]; // NonLinear.QuasiNewton();

            return r;
        }
    }
}